//
//  CategoriesViewController.m
//  iFoundIt
//
//  Created by Navid Shariat on 9/05/10.
//  Copyright 2010 QUT. All rights reserved.
//

#import "CategoriesViewController.h"


@implementation CategoriesViewController

@synthesize categoryList;
@synthesize imageArray;
@synthesize searchView;

- (void)dealloc {
	[categoryList release];
	[imageArray release];
	[searchView release];
    [super dealloc];
}

#pragma mark methods
- (NSMutableArray*) getAvailableCategoriesList{
	
//	NSArray * newArray=[[NSArray alloc] initWithObjects:@"bike", @"car", @"diary",@"Coles",@"Woolworths",@"milk",@"chees",nil];
	StorePersistentManager * manager=[[StorePersistentManager alloc] init];
	NSMutableArray*list= [manager getCategories];
	[manager release];
	return list;
}

- (void)viewDidLoad {
	[self setTitle:@"Categories"];
	NSMutableArray * newArray=[self getAvailableCategoriesList];
	[self setCategoryList:newArray];
	[newArray release];
}


- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [[self categoryList]count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
		//		[cell setAccessoryType: UITableViewCellAccessoryDisclosureIndicator];
		//		[cell setAccessoryType: UITableViewCellAccessoryDetailDisclosureButton];
    }
    
    // Set up the cell...
	NSUInteger row= [indexPath row];
	//	NSUInteger section=[indexPath section];
	
	[[cell textLabel]setText:[[self categoryList] objectAtIndex:row]];
	
	//	[[cell detailTextLabel] setText:@"detail"];
	//	[[cell imageView] setImage:[UIImage imageNamed:@"one.png"]];
	
    return cell;
}


#pragma mark Table view methods


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	NSUInteger row= [indexPath row];
	NSString * text= [[self categoryList] objectAtIndex:row];
	[[self searchView] setKeywordText:text];	
	//[[self view] removeFromSuperview];
	[[self navigationController] popViewControllerAnimated:YES];
}


@end

